package jp.co.itfrontier.mashup.command {
	import flash.net.URLRequest;
	import jp.co.itfrontier.mashup.utils.CrossDomainUtil;
	import flash.events.Event;
	import flash.net.URLLoader;
	import com.adobe.xml.syndication.rss.RSS20;
	import flash.display.Loader;
	import com.adobe.xml.syndication.rss.Item20;
	import jp.co.itfrontier.mashup.core.ModelLocater;
	import flash.events.EventDispatcher;
	
	[Event(name="complete", type="flash.event.Event")]
	public class KizasiRSSDelegate extends EventDispatcher {

		public function execute():void {
			
			var req:URLRequest = new URLRequest();
			req.url = "http://kizasi.jp/rss.xml";

			var proxy:CrossDomainUtil = new CrossDomainUtil();
			
			proxy.requestProxy(req, requestHandler);			
			
		}
		
		private function requestHandler(event:Event):void {
			var loader:URLLoader = event.target as URLLoader;
			if (loader == null) {
				return void;	
			}
			var rss:RSS20 = new RSS20();
			rss.parse(loader.data);
			
			ModelLocater.getInstance().kizasiRSS = rss.items;

			this.dispatchEvent(new Event(Event.COMPLETE));
			
		}


	}
}